import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.util.Log;

public class MainActivity extends Activity {

    private EditText productNameEditText;
    private EditText productPriceEditText;
    private TextView statusTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        productNameEditText = findViewById(R.id.product_name_edit_text);
        productPriceEditText = findViewById(R.id.product_price_edit_text);
        statusTextView = findViewById(R.id.status_text_view);
    }

    public void onUploadClick(View view) {
        String productName = productNameEditText.getText().toString();
        String productPriceStr = productPriceEditText.getText().toString();

        // 检查输入是否为空
        if (productName.isEmpty() || productPriceStr.isEmpty()) {
            statusTextView.setText("请输入完整信息");
            return;
        }

        double productPrice;
        try {
            // 将价格字符串转换为双精度数
            productPrice = Double.parseDouble(productPriceStr);
        } catch (NumberFormatException e) {
            // 如果转换出错，提示价格输入格式错误
            statusTextView.setText("价格输入格式错误");
            Log.e("Upload Error", "Invalid price format: " + productPriceStr);
            return;
        }

        // 这里可以添加实际的上架逻辑，比如与服务器交互等
        // 模拟上架成功
        statusTextView.setText(productName + " 成功上架，价格：" + productPrice);
    }
}